<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/thesame.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/page.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/leftSidebar.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/rightCon.css}" media="all">
</head>

<body class="layui-layout-body layui-layout-body-scroll">
<div class="layui-body">
    <!-- 内容主体区域 -->
    <div class="scroll-box bgWhite box-shadows border-radius4">
        <div class="scroll-box-padding">
            <div class="scroll-box-con">
                <div class="border-bot1px pb10px mb20px">
                    <div class="form-box form-style">
                        <div>
                            <div class="form-title">
                                <label>用户名称：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <input id="orgName" type="text" placeholder="请输入">
                                </p>
                            </div>
                        </div>
                        <div>
                            <div class="form-title">
                                <label>用户状态：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <select class="form-select-img" id="status">
                                        <option value="">请选择</option>
                                        <option value="1">启用</option>
                                        <option value="2">停用</option>
                                    </select>
                                </p>
                            </div>
                        </div>
                        <div class="form-box-btn overflow">
                            <span class="white border-radius4 border-blue blue inline-block pl20px pr20px lh30px cursor" id="serchBtn">查&nbsp;询</span>
                        </div>
                    </div>
                </div>
                <div>
                    <div class="mb20px lh32px overflow table-btn-img">
                        <p class="left">
                            <span onclick="addOrg()" class="white border-radius4 bgBlue-linear inline-block pl15px pr15px cursor"><img src="img/icon_add.png" th:src="@{/static/img/icon_add.png}">新建</span>
                        </p>
                        <p class="right">共<span class="red" id="count"></span>条数据</p>
                    </div>
                    <div class="border1px border-box border-radius4">
                        <table class="layui-hide" id="test" lay-filter="test"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="pop-con">
    <div class="pop-up">
        <!-- 停用提示 -->
        <!-- <div class="reset-con">
            <div>
                <div class="f16px"><img src="img/icon_stop.png">停用</div>
                <p>确认要停用此用户吗？</p>
            </div>
            <div class="btn-con textCenter">
                <span class="btn-cancel">取&nbsp;消</span>
                <span class="btn-submit">提&nbsp;交</span>
            </div>
        </div> -->
        <!-- 重置密码 -->
        <!-- <div class="reset-con">
            <div>
                <div class="f16px"><img src="img/icon_reset.png">重置密码</div>
                <p>是否要重置为初始密码123456？</p>
            </div>
            <div class="btn-con textCenter">
                <span class="btn-cancel">取&nbsp;消</span>
                <span class="btn-submit">提&nbsp;交</span>
            </div>
        </div> -->
        <!-- 修改密码 -->
        <!--<div class="amend-con form-style">
            <div class="pop-title relative overflow mb15px">
                <span class="ml15px f16px">修改密码</span>
                <p class="right"><img src="img/icon_close.png" th:src="@{/static/img/icon_close.png}" class="block pop-close">
                <p>
            </div>
            <div class="pop-form mt30px mb30px">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*</span>新密码：</label>
                    <div class="layui-input-block">
                        <input type="text" placeholder="请输入">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*</span>确认密码：</label>
                    <div class="layui-input-block">
                        <input type="text" placeholder="请输入">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block gray">密码应至少6位，且为大小写字母、数字和字符中至少两类的组合</div>
                </div>
            </div>
            <div class="btn-con textCenter">
                <span class="btn-cancel">取&nbsp;消</span>
                <span class="btn-submit">提&nbsp;交</span>
            </div>
        </div>-->
    </div>
</div>
<script src="js/jquery-3.1.1.min.js" th:src="@{/static/js/jquery-3.1.1.min.js}"></script>
<script src="layui/layui.js" th:src="@{/static/layui/layui.js}" charset="utf-8"></script>
<script src="js/selectColor.js" th:src="@{/static/js/selectColor.js}" charset="utf-8"></script>
<script>

    var currentPage = 0;

    $(function () {
        getData();

        $("#serchBtn").click(function () {
            getData();
        });

    });

    function getData() {
        //左侧菜单栏
        layui.use(['element', 'table', 'layer'], function () {
            var element = layui.element;
            var table = layui.table;
            var layer = layui.layer;
            //查询条件
            var orgName = $("#orgName").val();
            var status = $("#status").val();
            //第一个实例
            table.render({
                elem: '#test'
                //,url: '/demo/table/user/'
                ,
                url: "../org/getOrgList"
                , where: {
                    orgName: orgName, status: status
                },
                id: 'idTest'
                , request: {
                    pageName: 'currentPage' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                },
                page: true //开启分页
                , limit: 10 //每页显示的条数
                //,limits:[3,4,5]
                , groups: 9 //连续页码个数
                , parseData: function (res) {
                    console.log(res);
                    return {
                        "code": res.code,
                        "data": res.data.list,
                        "count": res.data.total,
                        "limit": res.data.pageSize,
                    };
                },
                cols: [
                    [ //表头
                        {
                            title: '序号',
                            fixed: 'left',
                            type: 'numbers',
                            width: 70,
                        }, {
                        field: 'orgName',
                        title: '用户名称',
                    }, {
                        field: 'userId',
                        title: '用户账号',
                    }, {
                        field: 'deviceNum',
                        title: '设备数',
                    }, {
                        field: 'startTime',
                        title: '开始时间',
                    }, {
                        field: 'overdueTime',
                        title: '到期时间',
                    }, {
                        field: 'fuck',
                        title: '状态',
                    }, {
                        field: 'operation',
                        title: '操作',
                        width: 200,
                        fixed: 'right',
                        templet: function (res) {
                            console.log(res);
                            var str = "";
                            if (res.status == 1) {
                                str += "<span class='red' onclick=\"userStop('" + res.id + "','1')\">停用</span></div>";
                            } else {
                                str += "<span class='blue' onclick=\"userStop('" + res.id + "','2')\">启用</span></div>";
                            }

                            return "<div class='table-list-btn cursor'>" +
                                "<span class='blue' onclick=\"toDetails('" + res.id + "')\">详情</span>" +
                                "<span class='blue' onclick=\"resetPwd('" + res.id + "')\">重置密码</span>" + str;
                        }
                    }
                    ]
                ], done: function (res, curr, count) {
                    $("#count").text(count);
                    currentPage = curr;
                }
            });
        });
    }

    //详情
    function toDetails(id) {
        window.location.href = "../org/toOrgDetailsPage?id=" + id
    }

    //新建
    function addOrg() {
        window.location.href = "../org/toAddOrgPage"
    }

    //重置密码
    function resetPwd(id) {
        var data = {id: id};
        layer.confirm('重置为初始密码123456吗', {
            btn: ['确定', '取消']
        }, function () {
            layer.closeAll();
            $.ajax({
                url: "../org/resetPwd",
                type: "post",
                async: false,
                dataType: "json",
                data: data,
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg(result.msg);
                        reloadData();
                    } else if (result.code == 101) {
                        layer.msg(result.msg);
                    }
                }
            })
        });
    }

    //停用、启用
    function userStop(id, status) {
        var str = "";
        if (status == 1) {
            str = "确定要停用吗"
        } else {
            str = "确定要启用吗"
        }
        var data = {id: id, flag: status};
        layer.confirm(str, {
            btn: ['确定', '取消']
        }, function () {
            layer.closeAll();
            $.ajax({
                url: "../org/orgStop",
                type: "post",
                async: false,
                dataType: "json",
                data: data,
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg(result.msg);
                        reloadData();
                    }
                }
            })
        });
    }

    //重载数据表格，停在当前页
    function reloadData() {
        //上述方法等价于
        layui.use(['element', 'laydate', 'table'], function () {
            var table = layui.table;
            table.reload('idTest', {
                page: {
                    curr: currentPage //重新从第 1 页开始
                }
            });
        })
    }

    function layerOpen() {
        layer.open({
            type: 1
            , title: false //不显示标题栏
            , closeBtn: false
            //新建组织
            , area: ['$("div#pop-con") + width() + "px"', '']
            , shade: 0.6
            , id: 'payCons' //设定一个id，防止重复弹出
            /*,btn: ['确认支付']*/
            , btnAlign: 'c'
            , moveType: 1 //拖拽模式，0或者1
            , shadeClose: true //设置允许点遮罩关闭
            , content: $("div#pop-con"),
            success: function () {
                //关闭弹层
                $(".pop-close").click(function () {
                    layer.closeAll();

                });
            },

        });
    }
</script>
</body>

</html>
